package com.wpp;
/*
 * 时间差计算第一种方法
 *
 *
 *
 *
 *
 * */


import org.junit.Test;

import java.util.Date;

public class TimeTest {

    @Test
    public void test() {
        long time = 0;
        long time2 = 0;
        StringBuffer s1 = new StringBuffer("");
        time = System.currentTimeMillis();
        System.out.println(time);
        for (int i = 0; i < 1000090; i++) {
            s1.append(i);
        }
        time2 = System.currentTimeMillis();
        System.out.println(time2);
        long l = time2 - time;
        System.out.println(l);


        StringBuilder s3 = new StringBuilder("");
        time = System.currentTimeMillis();
        System.out.println(time);
        for (int i = 0; i < 1000090; i++) {
            s3.append(i);
        }
        time2 = System.currentTimeMillis();
        System.out.println(time2);
        long l1 = time2 - time;
        System.out.println(l1);

        //java.util.Date
        Date date = new Date();
        date.getTime();//获取时间戳
        System.out.println(date.toString());//获取年月日
        System.out.println(date);//Thu Feb 18 19:30:27 CST 2021

        //java.sql.Date
        java.sql.Date date1 = new java.sql.Date(32974297919L);
        System.out.println(date1);//1971-01-17
        //java.util.Date 转换为 java.sql.Date
        Date date3 = new Date();
        java.sql.Date date2 = new java.sql.Date(date3.getTime());//因为两者之间关系为时间戳
        System.out.println(date2);

    }
}
